<?php

	require_once('config.php');
	require_once('core/core/debug.class.php');

	class db_connector {
		/**
		 * @var static $_instance
		 */
		public static $_instance = NULL;


		/**
		 * Singleton pattern
		 */
		public static function getInstance() {
			if (is_null(self::$_instance)) {
				$class = __CLASS__;
				self::$_instance = new $class();
			}
			return self::$_instance;
		}


		/**
		 * подключение к БД mysql
		 */
		public function connect($db_host, $db_user, $db_password, $db_name) {

		if (debug::endebug()) {
		  print "<p class='debug'>Дебаг режим для подключений к БД </p>";
		  print "<p>Host: " .$db_host;
		  print "<p>User: ".$db_user;
		  print "<p>Password: ".$db_password;
		  print "<p>Name DB: ".$db_name;
		}
		//подключение к бд
			try {
				#подключение к бд
				mysql_connect($db_host, $db_user, $db_password) or die (mysql_error());
//				print "yes!";
			} catch (Exception $e) {

				print $e->getFile();
				print $e->getLine();
				print $e->getMessage();
				exit(mysql_error());
			}

			try {
				//выбор бд
				mysql_select_db($db_name) or die(mysql_error());
			} catch (Exception $e) {

				print $e->getFile();
				print $e->getLine();
				print $e->getMessage();
				exit(mysql_error());
			}

		}

	}
?>

